/**
 * Created by xie on 2018/4/12.
 */
angular.module('service.mainpage', [
    'ngResource',
    'ngCookies'
])

    .service('MainpageService', ['$http', '$resource', '$cookies',
        function ($http, $resource, $cookies) {
            this.getArticleAll = function (success,error) {
                var resource = $resource(plantUrl + "article");
                return resource.query({},success,error)

            }
            this.getArticleById = function (articleid,success,error) {
                var resource = $resource(plantUrl + "article/"+articleid);
                return resource.get({articleid:articleid},success,error)
            }

            this.getArticleByType=function (articletype,success,error) {
                var resource = $resource(plantUrl + "article/getbytype");
                return resource.query({type:articletype},success,error)
            }

            this.getArticleByUserid=function (userid,success,error) {
                var resource = $resource(plantUrl + "article/getinfobyuserid");
                return resource.query({userid:userid},success,error)
            }

            this.addArticle=function (info,success,error) {
                var resource = $resource(plantUrl + "article/addinfo");
                return resource.save({},info,success,error)
            }

            this.getCommentByArticleid = function (articleid,success,error) {
                var resource = $resource(plantUrl + "Comment/selectbyarticleid");
                return resource.query({articleid:articleid},success,error)
            }

            this.addComment=function (info,success,error) {
                var resource = $resource(plantUrl + "Comment/addinfo");
                return resource.save({},info,success,error)
            }

            this.addDiss=function (info,success,error) {
                var resource = $resource(plantUrl + "diss/addinfo");
                return resource.save({},info,success,error)
            }

            this.getDissUser = function (articleid,success,error) {
                var resource = $resource(plantUrl + "diss/getuseridsbyarticleid");
                return resource.query({articleid:articleid},success,error)
            }

            this.deleteDissByKey = function (articleid,userid,success,error) {
                var resource = $resource(plantUrl + "diss/deleteinfo");
                return resource.remove({articleid:articleid,userid:userid},success,error)
            }
            this.deleteDissByArticleid = function (articleid,success,error) {
                var resource = $resource(plantUrl + "diss/deletebyarticle");
                return resource.remove({articleid:articleid},success,error)
            }

            this.deleteCommentByArticleid = function (articleid,success,error) {
                var resource = $resource(plantUrl + "Comment/deletebyarticle");
                return resource.remove({articleid:articleid},success,error)
            }
            this.deleteArticleByid = function (articleid,success,error) {
                var resource = $resource(plantUrl + "article/"+articleid);
                return resource.remove({articleid:articleid},success,error)
            }

        }])